CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++11 -g
LDFLAGS = -pthread

SOURCES = Acceptor.cc InetAddr.cc Socket.cc SocketIO.cc \
          TaskQueue.cc ThreadPool.cc TcpConnection.cc \
          MainReactor.cc SubReactor.cc EventLoop.cc TcpServer.cc \
          Timer.cc TimerQueue.cc LoadBalanceStrategy.cc Buffer.cc

SOURCES_WITH_TASK = $(SOURCES) Task.cc

# HTTP_SOURCES = HttpRequest.cc HttpResponse.cc HttpRouter.cc HttpServer.cc

OBJECTS = $(SOURCES:.cc=.o)
OBJECTS_WITH_TASK = $(SOURCES_WITH_TASK:.cc=.o)
HTTP_OBJECTS = $(HTTP_SOURCES:.cc=.o)

TARGET = multi_reactor_server
# TEST_TARGET = multi_reactor_test
# CLIENT_TARGET = multi_client_test
# HTTP_SERVER_TARGET = http_server
# HTTP_CLIENT_TARGET = http_client_test
# TIMER_TARGET = timer_test
# STRATEGY_TARGET = strategy_test

all: $(TARGET) 
# $(TEST_TARGET) $(CLIENT_TARGET) $(HTTP_SERVER_TARGET) $(HTTP_CLIENT_TARGET) $(TIMER_TARGET) $(STRATEGY_TARGET)

$(TARGET): $(OBJECTS_WITH_TASK) EchoServer.o test.o
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# $(TEST_TARGET): $(OBJECTS_WITH_TASK) MultiReactorTest.o
# 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# $(CLIENT_TARGET): MultiClientTest.o
# 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# $(HTTP_SERVER_TARGET): $(OBJECTS_WITH_TASK) $(HTTP_OBJECTS) HttpServerTest.o
# 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# $(HTTP_CLIENT_TARGET): HttpClientTest.o
# 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# $(TIMER_TARGET): $(OBJECTS_WITH_TASK) TimerTest.o
# 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# $(STRATEGY_TARGET): $(OBJECTS) StrategyTest.o
# 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

%.o: %.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	rm -f *.o $(TARGET) 
# 	$(TEST_TARGET) $(CLIENT_TARGET) $(HTTP_SERVER_TARGET) $(HTTP_CLIENT_TARGET) $(TIMER_TARGET) $(STRATEGY_TARGET) server.log client.log

.PHONY: all clean
